1 using System;
2 using System.Collections.Generic;
3 using System.ComponentModel;
4 using System.Data;
5 using System.Drawing;
6 using System.Linq;
7 using System.Text;
8 using System.Windows.Forms;
9 using System.Data.SqlClient;
10 using System.Security.Cryptography;
11 namespace WarehouseManagementSystem
12 {
13 public partial class frmUpdateProfile : Form
14 {
15 SqlDataReader rdr = null;
16 SqlConnection con = null;
17 SqlCommand cmd = null;
18 ConnectionString cs = new ConnectionString();
19 public frmUpdateProfile()
20 {
21 InitializeComponent();
22 }
23
24 private void btnUpdate_Click(object sender, EventArgs e)
25 {
26 try
27 {
28 if (txtCustomerName.Text == "")
29 {
30 MessageBox.Show("Please enter name", "Input Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
31 txtCustomerName.Focus();
32 return;
33 }
34
35 if (txtAddress.Text == "")
36 {
37 MessageBox.Show("Please enter address", "Input Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
38 txtAddress.Focus();
39 return;
40 }
41 if (txtCity.Text == "")
42 {
43 MessageBox.Show("Please enter city", "Input Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
44 txtCity.Focus();
45 return;
46 }
47
48 if (txtContactNo.Text == "")
49 {
50 MessageBox.Show("Please enter contact no.", "Input Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
51 txtContactNo.Focus();
52 return;
53 }
54 con = new SqlConnection(cs.DBConn);
55 con.Open();
56 string cb = "update Customer set Customername=@d2,address=@d3,City=@d4,ContactNo=@d5,ContactNo1=@d6,Email=@d7 where CustomerID=@d1";
57
58 cmd = new SqlCommand(cb);
59 cmd.Connection = con;
60 cmd.Parameters.AddWithValue("@d1", txtCustomerID.Text);
61 cmd.Parameters.AddWithValue("@d2", txtCustomerName.Text);
62 cmd.Parameters.AddWithValue("@d3", txtAddress.Text);
63 cmd.Parameters.AddWithValue("@d4", txtCity.Text);
64 cmd.Parameters.AddWithValue("@d5", txtContactNo.Text);
65 cmd.Parameters.AddWithValue("@d6", txtContactNo1.Text);
66 cmd.Parameters.AddWithValue("@d7", txtEmail.Text);
67 cmd.ExecuteReader();
68 MessageBox.Show("Successfully updated", "Customer Details", MessageBoxButtons.OK, MessageBoxIcon.Information);
69 btnUpdate.Enabled = false;
70 if (con.State == ConnectionState.Open)
71 {
72 con.Close();
73 }
74
75 con.Close();
76
77 }
78 catch (Exception ex)
79 {
80 MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
81 }
82 }
83
84
85
86
87 private void txtContactNo_KeyPress(object sender, KeyPressEventArgs e)
88 {
89 if (char.IsDigit(e.KeyChar) || char.IsControl(e.KeyChar))
90 {
91 e.Handled = false;
92 }
93 else
94 {
95 e.Handled = true;
96 }
97 }
98
99 private void txtContactNo1_KeyPress(object sender, KeyPressEventArgs e)
100 {
101 if (char.IsDigit(e.KeyChar) || char.IsControl(e.KeyChar))
102 {
103 e.Handled = false;
104 }
105 else
106 {
107 e.Handled = true;
108 }
109 }
110 public void Getdata()
111 {
112 con = new SqlConnection(cs.DBConn);
113 con.Open();
114 cmd = con.CreateCommand();
115
116 cmd.CommandText = "SELECT CustomerID,CustomerName,Address,City,ContactNo,ContactNo1,Email FROM Customer WHERE CustomerID = '" + txtCustomerID.Text.Trim() + "'";
117 rdr = cmd.ExecuteReader();
118
119 if (rdr.Read())
120 {
121 txtCustomerID.Text = (rdr.GetString(0).Trim());
122 txtCustomerName.Text = (rdr.GetString(1).Trim());
123 txtAddress.Text = (rdr.GetString(2).Trim());
124 txtCity.Text = (rdr.GetString(3).Trim());
125 txtContactNo.Text = (rdr.GetString(4).Trim());
126 txtContactNo1.Text = (rdr.GetString(5).Trim());
127 txtEmail.Text = (rdr.GetString(6).Trim());
128 }
129
130 if ((rdr != null))
131 {
132 rdr.Close();
133 }
134 if (con.State == ConnectionState.Open)
135 {
136 con.Close();
137 }
138 }
139 private void frmUpdateProfile_Load(object sender, EventArgs e)
140 {
141 Getdata();
142 }
143
144 }
145 }